package net.dopan.pigframe.config.utils;

import java.math.BigDecimal;
import java.text.DecimalFormat;

import org.apache.commons.lang.StringUtils;

public class StringCastInt {
	public  static int stringCastInt(String s){
		if(StringUtils.isNotBlank(s)){
			s=s.replaceAll(" ", "");
			return Integer.parseInt(s.trim());
		}
		return 0;
	}
	public static int  stringCastBigInt(String s){
		if(StringUtils.isNotBlank(s)){
			BigDecimal total= new BigDecimal(s).multiply(new BigDecimal("100"));
			return (int) Double.parseDouble(total.toString().trim());
		}
		return 0;
	}
	
	public static double stringCastDouble(String s){
		if(StringUtils.isNotBlank(s)){
			BigDecimal total= new BigDecimal(s).multiply(new BigDecimal("10"));
			BigDecimal discount= new BigDecimal(100).subtract(total);
			BigDecimal realDiscount = discount.divide(new BigDecimal(100));
			return Double.parseDouble(realDiscount.toString().trim());
		}
		return 0.0;
	}
	
	public static double StringCastDoubleFlat(String s){
	    System.out.println("折扣后的金额》》》》"+s);
		if(StringUtils.isNotBlank(s)){
			String money = new DecimalFormat("#.00").format(Double.parseDouble(s));
			return Double.parseDouble(money);
		}
		return 0.00;
	}
	public static int stringCastInt(char s) {
		// TODO Auto-generated method stub
		return s - '0';
	}
}
